package my.headfirstjava.observer.v3;

import java.util.Observable;
import java.util.Observer;

/**
 * author: xl
 * time: 2018/8/23 9:43
 * description:
 **/
public class CurrentWeather implements Observer,Display {

    private Observable observable= null;

    public CurrentWeather(Observable observable){
        this.observable =observable;
        observable.addObserver(this);
    }

    @Override
    public void display(WeatherData msg) {
        System.out.println("当前天气，温度:"+msg.getWendu());
        System.out.println("当前天气，湿度:"+msg.getShidu());
        System.out.println("当前天气，气压:"+msg.getQiya());
    }

    @Override
    public void update(Observable observable, Object arg) {
        if(observable instanceof Subject){
            WeatherData msg=((Subject) observable).getWeatherData();
            display(msg);
        }
    }
}
